<template>
	<el-dialog title="档案上架" v-model="visible" customClass="customWidth" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="库房编号" prop="roomId">
						<el-select v-model="form.roomId" clearable filterable remote :remote-method="remoteRoomMethod1" style="width: 100%" placeholder="输入档案编号">
							<el-option v-for="item in options1" :key="item.value" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="档案架编号" prop="frameId">
						<el-select v-model="form.frameId" clearable filterable remote :remote-method="remoteRoomMethod2" style="width: 100%" placeholder="输入档案编号">
							<el-option v-for="item in options2" :key="item.value" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="上架时间" prop="frameTime">
						<el-date-picker v-model="form.frameTime" placeholder="上架时间" type="date" value-format="YYYY-MM-DD" style="width: 100%;"></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="是否上架" prop="frameStatus">
						<el-radio-group v-model="form.frameStatus">
							<el-radio-button label="1">立即上架</el-radio-button>
							<el-radio-button label="0">暂不上架</el-radio-button>
						</el-radio-group>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">确 认</el-button>
		</template>
	</el-dialog>

</template>
<script>
import AttachMenu from "@/views/module/attachMenu.vue";
export default {
	emits: ['success', 'closed'],
	components: {
		AttachMenu,
	},
	data() {
		return {
			visible: false,
			isSaveing: false,
			options1: [],
			options2: [],
			form:{
				recordId:'',
				roomId:'',
				frameId:'',
				frameTime:'',
				frameStatus:'1'
			},
			rules: {
				frameId: [
					{required: true, message: '档案架编号不能为空', trigger: 'blur'}
				],
				roomId:[
					{required: true, message: '档案库房编号不能为空', trigger: 'blur'}
				],
				frameTime:[
					{required: true, message: '上传时间不能为空', trigger: 'blur'}
				]
			}
		}
	},
	mounted() {
		this.remoteRoomMethod1("");
		this.remoteRoomMethod2("");
	},
	methods: {
		//显示
		open() {
			this.visible = true;
			return this
		},
		async remoteRoomMethod1(query){
			let res = await this.$API.archives.archivesRoom.getArchivesRoomListForSelect.get({keyword:query});
			if (res.code == 200) {
				this.options1 = res.data
			}
		},
		async remoteRoomMethod2(query){
			let res = await this.$API.archives.archivesFrame.getArchivesFrameListForSelect.get({keyword:query});
			if (res.code == 200) {
				this.options2 = res.data
			}
		},
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = await this.$API.archives.archivesRecord.updateArchivesRecord.post(this.form);
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		setData(data) {
			this.form.recordId = data.recordId
			this.form.roomId = data.roomId
			this.form.frameId = data.frameId
			this.form.frameTime = data.frameTime;
			this.form.storagePeriod = data.storagePeriod
		}
	}
}
</script>

<style>
.customWidth {
	width: 60%;
}
</style>
